<!DOCTYPE html>
<html lang="en">

<head>
    <script src="/public/js/jquery-3.3.1.min.js"></script>
    <meta http-equiv="Content-Type" content="register/html; charset=gb2312">
    <title>注册</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        html {
            height: 100%;
            width: 100%;
            overflow: hidden;
            margin: 0;
            padding: 0;
            background: url(/public/img/loginregistBack.png) no-repeat 0px 0px;
            background-repeat: no-repeat;
            background-size: 100% 100%;
            -moz-background-size: 100% 100%;
        }

        body {
            display: flex;
            align-items: center;
            justify-content: center;
            height: 100%;
        }

        #loginDiv {
            width: 37%;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 650px;
            background-color: rgba(75, 81, 95, 0.3);
            box-shadow: 7px 7px 17px rgba(52, 56, 66, 0.5);
            border-radius: 5px;
        }

        #name_trip {
            margin-left: 50px;
            color: red;
        }

        p,
        .sexDiv {
            margin-top: 10px;
            margin-left: 20px;
            color: azure;
        }

        .sexDiv>input,
        .hobby>input {
            width: 30px;
            height: 17px;
        }

        input,
        select {
            margin-left: 15px;
            border-radius: 5px;
            border-style: hidden;
            height: 30px;
            width: 140px;
            background-color: rgba(216, 191, 216, 0.5);
            outline: none;
            color: #f0edf3;
            padding-left: 10px;
        }

        .button {
            border-color: cornsilk;
            background-color: rgba(100, 149, 237, .7);
            color: aliceblue;
            border-style: hidden;
            border-radius: 5px;
            width: 100px;
            height: 31px;
            font-size: 16px;
        }

        .introduce {
            margin-left: 110px;
        }

        .introduce>textarea {
            background-color: rgba(216, 191, 216, 0.5);
            border-style: hidden;
            outline: none;
            border-radius: 5px;
        }

        h1 {
            text-align: center;
            margin-bottom: 20px;
            margin-top: 20px;
            color: #f0edf3;
        }

        b {
            margin-left: 50px;
            color: #FFEB3B;
            font-size: 10px;
            font-weight: initial;
        }
    </style>
</head>

<body>
<div id="loginDiv">
    <form action="">
        <h1>注册</h1>
        <p>
            用户姓名:
            <input id="username" name="username" type="text" autofocus required>
            <label id="name_trip"></label>
        </p>

        <p>
            用户密码:
            <input id="password" name="password" type="password" required>
            <label id="password_trip"></label>
        </p>

        <p>
            确认密码:
            <input id="surePassword" type="password" required>
            <label id="surePassword_trip"></label>
        </p>

        <p>
        <div class="sexDiv">
            用户性别:
            <input class="userSex" name="sex" value="男" checked type="radio">男
            <input class="userSex" name="sex" value="女" type="radio">女
            <label id="sex_trip"></label>
        </div>
        <p>
            手机号:
            <input id="tel" name="tel" type="text">
            <label id="birthday_trip"></label>
        </p>
        <p>
            电子邮件:
            <input id="email" name="email" type="email" required>
            <label id="emil_trip"></label>
        </p>
        <p> 自我介绍:</p>
        <div class="introduce">
            <textarea name="introduce" cols="30" id="introduceText" required rows="10"></textarea>
            <label id="introduce_trip"></label>
        </div>
        <p style="text-align: center;">
            <input type="button" class="isbutton" value="提交">
            <input type="reset" class="button" value="重置">
        </p>
    </form>
</div>

</body>
<script type="text/javascript">
    $('.isbutton').on('click',function() {
        var booluser = $('#username')[0].value.length >= 3;
        var boolpwd = $('#password')[0].value.length >= 3;
        var boolpwd1 = $('#password')[0].value == $('#surePassword')[0].value;
        var retel = /^(13[0-9]|14[5|7]|15[0|1|2|3|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\d{8}$/g;
        var booltel = retel.test($('#tel')[0].value);
        var reemail = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/g;
        var boolemail = reemail.test($('#email')[0].value);            //这里应该嵌套使if的,但是不是实际开发,这么写便于代码观看
        if (!booluser) {
            console.log('user:不能少于8位');
        }
        if (!boolpwd) {
            console.log('pwd:不能少于6位');
        }
        if (!boolpwd1) {
            console.log('pwd1:两次输入密码不一致');
        }
        if (!booltel) {
            console.log('tel:请输入正确的电话号');
        }
        if (!boolemail) {
            console.log('email:请输入正确的邮箱格式');
        }

        if (booluser && boolpwd && boolpwd1 && booltel && boolemail){
            $.ajax({
                url:"/index.php?c=RegisterMatch&a=checked",
                type:"POST",
                data:{
                    username:$("input[name='username']").val(),
                    password:$("input[name='password']").val(),
                    sex:$("input[name='sex']").val(),
                    tel:$("input[name='tel']").val(),
                    email:$("input[name='email']").val(),
                    introduce:$('#introduceText').val()
                },
                dataType:"json",
                success:function (data){
                    console.log(data)
                    if (data.flag){
                        alert(data.msg);
                        location.href="/index.php?c=Login&a=LoginFucntion";
                    }else {
                        alert(data.msg);
                    }
                },
                error:function (){
                    alert("请求失败")
                }
            });
        }
    });


</script>
</html>

